<template>
  <div class="demo">
    <div class="demo-title">高级搜索</div>
    <div class="demo-content">
      <Form
        ref="formRef"
        name="advanced_search"
        class="ant-advanced-search-form"
        :model="formState"
        @finish="onFinish"
      >
        <Row :gutter="24">
          <template v-for="i in 10" :key="i">
            <Col v-show="expand || i <= 6" :span="8">
              <Form.Item
                :name="`field-${i}`"
                :label="`field-${i}`"
                :rules="[{ required: true, message: 'input something' }]"
              >
                <Input v-model:value="formState[`field-${i}`]" placeholder="placeholder"></Input>
              </Form.Item>
            </Col>
          </template>
        </Row>
        <Row>
          <Col :span="24" style="text-align: right">
            <Button type="primary" html-type="submit">Search</Button>
            <Button style="margin: 0 8px" @click="() => formRef?.resetFields()">Clear</Button>
            <a style="font-size: 12px" @click="expand = !expand">
              <template v-if="expand">
                <UpOutlined />
              </template>
              <template v-else>
                <DownOutlined />
              </template>
              Collapse
            </a>
          </Col>
        </Row>
      </Form>
      <div class="search-result-list">Search Result List</div>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { reactive, ref } from 'vue';
  import { DownOutlined, UpOutlined } from '@ant-design/icons-vue';
  import Button from '@sscd/button';
  import { Col, Row } from '@sscd/grid';
  import Input from '@sscd/input';
  import Form from '@sscd/form';
  import type { FormInstance } from '@sscd/form';
  const expand = ref(false);
  const formRef = ref<FormInstance>();
  const formState = reactive({});
  const onFinish = (values: any) => {
    console.log('Received values of form: ', values);
    console.log('formState: ', formState);
  };
</script>
